package com.bl.car.controller;

import com.bl.car.entity.Admin;
import com.bl.car.repositiy.AdminRepository;
import com.bl.car.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 后端 接口
 *
 * @author zhx
 * @create 2017-11-16 17:42
 **/
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private AdminRepository adminRepository;

    @PostMapping("/login")
    public Result<Admin> login(@RequestParam("userName")String userName,@RequestParam("pwd") String pwd){
        //判断非空
        Admin userByUsername = adminRepository.getAdminByUsername(userName);

        if(userByUsername == null){
            return Result.error("用户名错误");
        }

        if(userByUsername.getPwd().equals(pwd)){
            return Result.ok(userByUsername);
        }else{
            return Result.error("密码错误!");
        }
    }

}
